package com.yuwei.order

import com.yuwei.common.mvi.BaseViewModel
import com.yuwei.database.RoomDBUtils.getAddressDao
import com.yuwei.database.RoomDBUtils.getOrderDao

class OrderViewModel: BaseViewModel<OrderApiService, OrderIntent>() {
    override fun handleIntent(intent: OrderIntent) {
        when(intent){
            is OrderIntent.insertOrder -> {
                roomRequest({ getOrderDao().insertOrder(intent.orderEntity) },"insertOrder")
            }
            is OrderIntent.updateOrder ->{
                roomRequest({ getOrderDao().update(intent.orderEntity) },"updateOrder")
            }
            is OrderIntent.getAllAddress ->{
                roomRequest({getAddressDao().getAll()},"getAllAddress")
            }
            is OrderIntent.insertAddress ->{
                roomRequest({ getAddressDao().insertAddress(intent.addressEntity)},"insertAddress")
            }
            is OrderIntent.updateAddress ->{
                roomRequest({ getAddressDao().update(intent.addressEntity)},"updateAddress")
            }
            is OrderIntent.getByStatus->{
                roomRequest({ getOrderDao().getByStatus(intent.status)},"getByStatus")
            }
        }
    }
}